<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2019-06-28
  Time: 9:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String pash = request.getContextPath();
    String basepash = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + pash + "/";
%>
<html>
<head>
    <base href="<%=basepash%>">
    <%@include file="/publs.jsp"%>
    <title>Title</title>
</head>
<body>
<div id="root">

    <Modal title="添加角色" v-model="showhidess" @on-ok="insert">
        <i-form :label-width="80">
            <form-item label="角色名称">
                <i-input v-model="names"></i-input>
            </form-item>
        </i-form>
    </Modal>


    <Modal title="角色授权" v-model="showhidesssssss" @on-ok="jueseshouquan">
        <tree ref="sqsq" :data="treeData" style="margin-left:50px" show-checkbox multiple></tree>
    </Modal>



    <shiro:hasPermission name="users:juesetype">
        <i-button @click="insertas" type="primary" style="margin-left: 50px;margin-top: 20px;">添加</i-button>
    </shiro:hasPermission>

    <i-table height="300" style="margin-top:20px;margin-right: 50px;margin-left: 50px;" :data="datas" :columns="colunmsss" border>
        <template slot="caozuo" slot-scope="{row}">
            <i-button size="small"  v-if="row.id!=1" type="info" @click="shouquan(row)">授权</i-button>

        </template>
    </i-table>





    <Modal title="添加部门" v-model="showhidessss" @on-ok="inserts">
        <i-form :label-width="80">
            <form-item label="部门名称">
                <i-input v-model="namessss"></i-input>
            </form-item>
        </i-form>
    </Modal>

    <shiro:hasPermission name="users:juesetype">
        <i-button @click="insertasss" type="primary" style="margin-left: 50px;margin-top: 20px;">添加</i-button>
    </shiro:hasPermission>

    <i-table height="300" style="margin-top:20px;margin-right: 50px;margin-left: 50px;" :data="datasasd" :columns="colunmsssasd" border>
    </i-table>


</div>
<script>
    let _this = null;
    new Vue({
        el:"#root",
        data:{
            namessss:"",
            datas:[],
            datasasd:[],
            showhidesssssss:false,
            obj:{},
            colunmsssasd:[
                {
                    title:"编号",
                    key:"bumenid"
                },{
                    title:"部门",
                    key:"bumenname"
                }
            ],
            showhidess:false,
            showhidessss:false,
            colunmsss:[
                {
                    title:"编号",
                    key:"id"
                },{
                    title:"角色名称",
                    key:"posi"
                }
                <shiro:hasPermission name="users:sqaupd">
                ,{
                    titlw:"操作",
                    slot:"caozuo"
                }
                </shiro:hasPermission>
            ],
            heights:0,
            names:"",
            treeData:[]
        },
        methods:{
            select(){
                axios.get("/users/ueerTypes").then(({data})=>{
                    _this.datas = data.obj;
                })
            },
            insertas(){
                _this.showhidess = true;
            },
            insertasss(){
                _this.showhidessss = true;
            },
            insert(){
                axios.get("/users/ueerTypesintser?name="+this.names).then(({data})=>{
                    iview.Message.info(data.msg);
                    _this.names = "";
                    _this.select();
                })
            },
            inserts(){
                axios.get("/users/bumen?names="+this.namessss).then(({data})=>{
                    iview.Message.info(data.msg);
                    _this.namessss = "";
                    _this.selectasd();
                })
            },
            selectasd(){
                axios.get("/users/bumenMapper").then(({data})=>{
                    _this.datasasd = data.obj;
                })
            },
            //树形菜单--树形菜单--树形菜单--树形菜单--树形菜单--树形菜单--树形菜单--树形菜单
            shouquan(row){
                this.obj = row;
                this.tres();
                this.showhidesssssss = true;
            },
            tres(){
                axios.get("/shuxing?id="+this.obj.id).then(({data})=>{
                    this.treeData = data.obj;
                })
            },
            jueseshouquan(){
                let sqsq = this.$refs.sqsq.getCheckedAndIndeterminateNodes();
                let params = "id="+this.obj.id;
                for (let i = 0; i < sqsq.length; i++) {
                    params += "&ids=" + sqsq[i].id
                }
                // console.log(params);
                axios.get("/doShouQaun?" +params).then(({data})=>{
                    iview.Message.warning(data.msg)
                })
            }
        },
        mounted(){
            this.select();
            _this.selectasd();
        },
        created(){
            _this = this;
        }
    })
</script>
</body>
</html>
